// pages/college/college.js
Page({

  data: {
     curNav:1,
     curIndex:1,

     // 侧边栏名称
     navList:[
       {
         id:0,
         name:'北京'
       },
       {
         id:1,
         name:'天津'
       },
       {
         id:2,
         name:'上海'
       },
       {
         id:3,
         name:'重庆'
       },
       {
         id:4,
         name:'江苏'
       },
       {
         id:5,
         name:'浙江'
       },
       {
         id:6,
         name:'湖北'
       },
       {
         id:7,
         name:'广东'
       },
       {
         id:8,
         name:'四川'
       },
       {
         id:9,
         name:'湖南'
       },
       {
         id:10,
         name:'厦门'
       }
     ],   

  },

  onLoad() {
    this.getcolleges();
  },


  getcolleges:function(){
    var mark = 'getcolleges';
    wx.request({
      url: 'http://localhost:8080/youYanZaiXian/CollegeServlet',
      method: 'POST',
      data:{
        mark:mark,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded',
        'Accept': 'application/json'
      },
      success: (res)=>{
        var cList = res.data.data.cList;
        this.setData({
          cList:cList,
        })
        //console.log(this.data.cList)
        this.processDate();  // 由于异步而在此处调用
      }
    });
  },

  processDate:function(){
    var cList = this.data.cList;
    var collegeList = [11];
    for(var i=0;i<=10;i++){
      var count=0;
      collegeList[i] = new Array();
      for(var j=0;j<cList.length;j++){
        if(cList[j].collegeProvince==i){
          collegeList[i][count] = cList[j];
          count = count+1;
        }
      }
    }
    //console.log(collegeList);
    this.setData({
      collegeList:collegeList,
    })
    
  },

  selectNav(event) {
    let id = event.target.dataset.id,
      index = parseInt(event.target.dataset.index);
    self = this;
    this.setData({
      curNav: id,
      curIndex: index
    })
    //console.log(this.data.curIndex)
  },
  
  
  toCollegeDetail: function (e) {
    var cName = e.currentTarget.dataset.name;
    var collegeid = e.currentTarget.dataset.collegeid;
    wx.navigateTo({
      url: '/pages/college/collegeDetail/collegeDetail?collegeid='+collegeid,
    })
    wx.setNavigationBarTitle({
      title: cName,
    })
  }

})